package com.taxshare.seller.util;

import java.util.HashMap;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.alibaba.fastjson.JSON;

import sun.misc.BASE64Decoder;

public class ParseUtil {

    public static Map<String,Object> parseRes(String res){
        Map<String,Object> resMap = new HashMap();
        try{
            Document doc = DocumentHelper.parseText(res);
            Element ebody = doc.getRootElement().element("BODY");
            String body = decodeBase64(ebody.getText());
            System.out.println(body);
            resMap = (Map<String, Object>) JSON.parse(body);
        }catch (Exception e){
            e.printStackTrace();
        }
        return resMap;
    }
    
    
    /**base64解码*/
    public static String decodeBase64 (String str) throws Exception{
        BASE64Decoder base64 = new BASE64Decoder();
        String decode = null;
        try {
            decode = new String(base64.decodeBuffer(str),"utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return decode;
    }
}
